/**
 * Copyright (c) 2009-2012 XTEAM
 * All rights reserved.
 */
/**
 * File：GoodsAction.java
 * History:
 *         2012-12-19: Initially created, Chrise.
 */
package com.xteam.ecsystem.action;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.xteam.ecsystem.base.Constant;
import com.xteam.ecsystem.system.ConfigManager;
import com.xteam.ecsystem.utils.FrontUtil;

/**
 * 商品请求控制层。
 * @author Chrise
 */
@Controller
public class GoodsAction {
	
	@Autowired
	private ConfigManager cfgManager;
	
	/**
	 * 商品列表请求。
	 * @author Chrise 2012-12-19
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/category.xhtml", method = RequestMethod.GET)
	public String list(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws IOException {
		//获取模板路径
		String template = FrontUtil.getTemplatePath(request, response, this.cfgManager);
		if (template != null) {
			//设置公共数据
			FrontUtil.setCommons(request, response, model, this.cfgManager.getSystemConfig(), this.cfgManager.getWebConfig());
			
			//设置数据
			model.put(Constant.VAR_KEYWORDS.value(), FrontUtil.getStringParam(request, "keywords", ""));
			model.put(Constant.VAR_PRICEMAX.value(),FrontUtil.getIntegerParam(request, "pricemax", 0));
			model.put(Constant.VAR_PRICEMIN.value(),FrontUtil.getIntegerParam(request, "pricemin", 0));
			model.put(Constant.VAR_SELECTEDATTR.value(), FrontUtil.getStringParam(request, "selectedattr", ""));
			model.put(Constant.VAR_SELECTEDTATTRI.value(), FrontUtil.getStringParam(request, "selectedtattri", ""));
			model.put(Constant.VAR_GOODSBRAND.value(), FrontUtil.getStringParam(request, "brand", "0"));
			model.put(Constant.VAR_GOODSTYPE.value(), FrontUtil.getStringParam(request, "type", ""));
			model.put(Constant.VAR_GOODSGROUP.value(), FrontUtil.getStringParam(request, "group", "0"));
			model.put(Constant.VAR_PAGEINDEX.value(), FrontUtil.getIntegerParam(request, "index", 1));
			model.put(Constant.VAR_PAGESIZE.value(), this.cfgManager.getSystemConfig().getSscGlpagesize());
		}
		
		return template;
	}
	
	/**
	 * 
	 * 商品分类查询
	 * @author ls
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/category.xhtml", method = RequestMethod.POST)
	public String listPost(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws IOException {
		//获取模板路径
		String template = FrontUtil.getTemplatePath(request, response, this.cfgManager);
		if (template != null) {
			//设置公共数据
			FrontUtil.setCommons(request, response, model, this.cfgManager.getSystemConfig(), this.cfgManager.getWebConfig());
			
			//设置数据
			model.put(Constant.VAR_KEYWORDS.value(), FrontUtil.getStringParam(request, "keywords", ""));
			model.put(Constant.VAR_PRICEMAX.value(),FrontUtil.getIntegerParam(request, "pricemax", 0));
			model.put(Constant.VAR_PRICEMIN.value(),FrontUtil.getIntegerParam(request, "pricemin", 0));
			model.put(Constant.VAR_SELECTEDATTR.value(), FrontUtil.getStringParam(request, "selectedattr", ""));
			model.put(Constant.VAR_SELECTEDTATTRI.value(), FrontUtil.getStringParam(request, "selectedtattri", ""));
			model.put(Constant.VAR_GOODSBRAND.value(), FrontUtil.getStringParam(request, "brand", "0"));
			model.put(Constant.VAR_GOODSTYPE.value(), FrontUtil.getStringParam(request, "type", ""));
			model.put(Constant.VAR_GOODSGROUP.value(), FrontUtil.getStringParam(request, "group", "0"));
			model.put(Constant.VAR_PAGEINDEX.value(), FrontUtil.getIntegerParam(request, "index", 1));
			model.put(Constant.VAR_PAGESIZE.value(), this.cfgManager.getSystemConfig().getSscGlpagesize());
	
		}
		
		return template;
	}
	
	/**
	 * 
	 * 商品信息请求
	 * @author ls
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/goods.xhtml", method = RequestMethod.GET)
	public String goods(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws IOException {
		//获取模板路径
		String template = FrontUtil.getTemplatePath(request, response, this.cfgManager);
		if (template != null) {
			//设置公共数据
			FrontUtil.setCommons(request, response, model, this.cfgManager.getSystemConfig(), this.cfgManager.getWebConfig());
			
			//设置数据
			model.put(Constant.VAR_GOODSGROUP.value(), FrontUtil.getStringParam(request, "group", "0"));
			model.put(Constant.VAR_GOODSID.value(), FrontUtil.getStringParam(request, "id", ""));
		}
		
		return template;
	}
	
	@RequestMapping(value = "/search.xhtml", method = RequestMethod.GET)
	public String typelist(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws IOException {
		//获取模板路径
		String template = FrontUtil.getTemplatePath(request, response, this.cfgManager);
		if (template != null) {
			//设置公共数据
			FrontUtil.setCommons(request,response, model, this.cfgManager.getSystemConfig(), this.cfgManager.getWebConfig());
			
			//设置数据
			model.put(Constant.VAR_KEYWORDS.value(), FrontUtil.getStringParam(request, "keywords", ""));
			model.put(Constant.VAR_PRICEMAX.value(),FrontUtil.getIntegerParam(request, "pricemax", 0));
			model.put(Constant.VAR_PRICEMIN.value(),FrontUtil.getIntegerParam(request, "pricemin", 0));
			model.put(Constant.VAR_SELECTEDATTR.value(), FrontUtil.getStringParam(request, "selectedattr", ""));
			model.put(Constant.VAR_GOODSTYPE.value(), FrontUtil.getStringParam(request, "type", ""));
			model.put(Constant.VAR_GOODSGROUP.value(), FrontUtil.getStringParam(request, "group", ""));
			model.put(Constant.VAR_GOODSBRAND.value(), FrontUtil.getStringParam(request, "brand", "0"));
			model.put(Constant.VAR_PAGEINDEX.value(), FrontUtil.getIntegerParam(request, "index", 1));
			model.put(Constant.VAR_PAGESIZE.value(), 10);
		}
		
		return template;
	}
}
